	**************************************************************
	* Figure A.2: Relative Frequency of Significant Predictors of 
	* Individual-level Vote Choice in Referendums, 1981-2009 
	* (Individual-level Data)
	**************************************************************
	
	capture mkdir "vote_choice"
	
	* (i) Estimation for Groups with 2 categories
	
	local var "group_gender group_urban group_employed group_gov_trust group_interest group_language"
	foreach x of local var{
	
	
	use data4.dta, clear
	
	display `x' // sample restriction 1: drop all with missing values
	drop if `x'==.
	bysort anrbfs_num: egen `x'_max=max(`x' )
	bysort anrbfs_num:  egen `x'_min=min(`x' ) 
	bysort anrbfs_num:  egen `x'_med=mad(`x') 
	drop if `x'_max<2 | `x'_min>1 // sample restriction 2: drop all referendums without sufficient number of categories
	drop `x'_max `x'_min `x'_med
	
	keep if turnout==1 // keep only voters. 	
	drop if canton==. // sample restriction
	egen anrbfs_num_`x'=group(anrbfs_num) // group specific referendum index
	sum anrbfs_num_`x'
	local anrbfs_num_max=r(max)
	matrix beta=J(`anrbfs_num_max',1,.)
	matrix beta_se=J(`anrbfs_num_max',1,.)
	matrix beta_marginal=J(`anrbfs_num_max',1,.)
	matrix beta_marginal_se=J(`anrbfs_num_max',1,.)


	forvalues i=1(1)`anrbfs_num_max'{ 		// loop all referendums
	display `i'
	
	
	probit votechoice   i.`x'  i.canton   if anrbfs_num_`x'==`i'  
		 
	// (a) save coefficients

	matrix beta1=e(b)'
	matrix beta_cov1=e(V)
	matrix beta[`i',1]=beta1[2,1]
	matrix beta_se[`i',1]=sqrt(beta_cov1[2,2])
	
	// (b) save marginal effects
	
	margins, at((mean)  _all ) dydx(`x')  
	matrix beta_cov1=r(V)
	matrix beta1=r(b)'
	matrix beta_marginal[`i',1]=beta1[2,1]
	matrix beta_marginal_se[`i',1]=sqrt(beta_cov1[2,2])				
	
	}

		
		
	svmat beta, names(beta)
	svmat beta_se, names(beta_se)
	svmat beta_marginal, names(beta_marginal)
	svmat beta_marginal_se, names(beta_marginal_se)

	keep beta*
	keep if beta_se1!=.
	save ./vote_choice/votechoice_`x'.dta, replace
	}
	
	
	

	* (ii) Estimation for Groups with 3 categories
	
	local var "group_educ group_age  group_orientation group_religion group_orientation_alt group_participation group_party group_income"
	foreach x of local var{
	
	use data4.dta, clear
		
	display `x' // sample restriction 1: drop all with missing values
	drop if `x'==.
	bysort anrbfs_num: egen `x'_max=max(`x' )
	bysort anrbfs_num:  egen `x'_min=min(`x' ) 
	bysort anrbfs_num:  egen `x'_med=mad(`x') 
	drop if `x'_max<3 | `x'_min>1 // sample restriction 2: drop all referendums without sufficient number of categories
	drop `x'_max `x'_min `x'_med
	
	keep if turnout==1 // keep only voters. 
	
	drop if canton==. // sample restriction
	egen anrbfs_num_`x'=group(anrbfs_num) // group specific referendum index
	sum anrbfs_num_`x'
	local anrbfs_num_max=r(max)
	matrix beta=J(`anrbfs_num_max',2,.)
	matrix beta_se=J(`anrbfs_num_max',2,.)
	matrix beta_marginal=J(`anrbfs_num_max',2,.)
	matrix beta_marginal_se=J(`anrbfs_num_max',2,.)
	

	forvalues i=1(1)`anrbfs_num_max'{ // loop all referendums
	display `i'
	
	probit votechoice   i.`x' ///
		 i.canton   if anrbfs_num_`x'==`i'  

	
	
	// (a) save coefficients

	matrix beta1=e(b)'
	matrix beta_cov1=e(V)
	matrix beta[`i',1]=beta1[2,1]
	matrix beta[`i',2]=beta1[3,1]
	matrix beta_se[`i',1]=sqrt(beta_cov1[2,2])
	matrix beta_se[`i',2]=sqrt(beta_cov1[3,3])
	
	// (b) save marginal effects
	
	margins, at((mean)  _all ) dydx(`x')  
	matrix beta_cov1=r(V)
	matrix beta1=r(b)'
	matrix beta_marginal[`i',1]=beta1[2,1]
	matrix beta_marginal[`i',2]=beta1[3,1]
	matrix beta_marginal_se[`i',1]=sqrt(beta_cov1[2,2])				
	matrix beta_marginal_se[`i',2]=sqrt(beta_cov1[3,3])				
	
	}

		
		
	svmat beta, names(beta)
	svmat beta_se, names(beta_se)
	svmat beta_marginal, names(beta_marginal)
	svmat beta_marginal_se, names(beta_marginal_se)

	keep beta*
	keep if beta_se1!=.
	save ./vote_choice/votechoice_`x'.dta, replace
	}

	* (iii) Estimation for Groups with four categories
	
	local var "group_party_iden"
	foreach x of local var{
	
	use data4.dta, clear
	
	rename group_party_identification group_party_iden
		
	display `x' // sample restriction 1: drop all with missing values
	drop if `x'==.
	bysort anrbfs_num: egen `x'_max=max(`x' )
	bysort anrbfs_num:  egen `x'_min=min(`x' ) 
	bysort anrbfs_num:  egen `x'_med=mad(`x') 
	drop if `x'_max<3 | `x'_min>1 // sample restriction 2: drop all referendums without sufficient number of categories
	drop `x'_max `x'_min `x'_med
	
	keep if turnout==1 // keep only voters. 
	
	drop if canton==. // sample restriction
	egen anrbfs_num_`x'=group(anrbfs_num) // group specific referendum index
	sum anrbfs_num_`x'
	local anrbfs_num_max=r(max)
	matrix beta=J(`anrbfs_num_max',4,.)
	matrix beta_se=J(`anrbfs_num_max',4,.)
	matrix beta_marginal=J(`anrbfs_num_max',4,.)
	matrix beta_marginal_se=J(`anrbfs_num_max',4,.)
	

	forvalues i=1(1)`anrbfs_num_max'{ 		// loop all referendums
	display `i'
	
	probit votechoice   i.`x' i.canton   if anrbfs_num_`x'==`i'  

	
	
	// (a) save coefficients

	matrix beta1=e(b)'
	matrix beta_cov1=e(V)
	matrix beta[`i',1]=beta1[2,1]
	matrix beta[`i',2]=beta1[3,1]
	matrix beta[`i',3]=beta1[4,1]
	matrix beta[`i',4]=beta1[5,1]
		
	matrix beta_se[`i',1]=sqrt(beta_cov1[2,2])
	matrix beta_se[`i',2]=sqrt(beta_cov1[3,3])
	matrix beta_se[`i',3]=sqrt(beta_cov1[4,4])
	matrix beta_se[`i',4]=sqrt(beta_cov1[5,5])

	// (b) save marginal effects
	
	margins, at((mean)  _all ) dydx(`x')  
	matrix beta_cov1=r(V)
	matrix beta1=r(b)'
	matrix beta_marginal[`i',1]=beta1[2,1]
	matrix beta_marginal[`i',2]=beta1[3,1]
	matrix beta_marginal[`i',3]=beta1[4,1]
	matrix beta_marginal[`i',4]=beta1[5,1]
	
	
	matrix beta_marginal_se[`i',1]=sqrt(beta_cov1[2,2])				
	matrix beta_marginal_se[`i',2]=sqrt(beta_cov1[3,3])				
	matrix beta_marginal_se[`i',3]=sqrt(beta_cov1[4,4])				
	matrix beta_marginal_se[`i',4]=sqrt(beta_cov1[5,5])			
		
	}

		
		
	svmat beta, names(beta)
	svmat beta_se, names(beta_se)
	svmat beta_marginal, names(beta_marginal)
	svmat beta_marginal_se, names(beta_marginal_se)

	keep beta*
	keep if beta_se1!=.
	save ./vote_choice/votechoice_`x'.dta, replace
	}

	
	// (iv) append all groups
	
	use ./vote_choice/votechoice_group_party_iden.dta, clear

	capture gen variable="group_party_iden"
	local count_var=1
	gen variable_num=1

	
	local var "group_orientation group_interest group_party_iden group_gov_trust group_age group_educ group_employed group_income group_language group_religion group_urban"
	foreach x of local var{   // sample restriction 1: drop all with missing values
	local count_var=`count_var' +1
	append using ./vote_choice/votechoice_`x'.dta
	replace variable="`x'" if  variable==""
	replace variable_num=`count_var' if  variable_num==.
	}
	
	gen beta1_t=abs(beta1/beta_se1)
	gen beta2_t=abs(beta2/beta_se2)	
	gen beta3_t=abs(beta3/beta_se3)
	gen beta4_t=abs(beta4/beta_se4)		

		
	
	gen significant1=0
	replace significant1=1 if beta1_t>=1.96
	gen significant2=0
	replace significant2=1 if beta2_t>=1.96 & !missing(beta2_t)
	gen significant3=0
	replace significant3=1 if beta3_t>=1.96 & !missing(beta3_t)
	gen significant4=0
	replace significant4=1 if beta4_t>=1.96 & !missing(beta4_t)
	
	bysort variable: egen signficant1_total=sum(significant1)
	bysort variable: egen signficant2_total=sum(significant2)
	bysort variable: egen signficant3_total=sum(significant3)
	bysort variable: egen signficant4_total=sum(significant4)
	
	
	bysort variable: gen N_estimations=_N
	
	gen significant_share1=signficant1_total/N_estimations
	gen significant_share2=signficant2_total/N_estimations
	gen significant_share3=signficant3_total/N_estimations
	gen significant_share4=signficant4_total/N_estimations

				
	bysort variable: gen indi=_n
	keep if indi==1
	
	keep variable	variable_num significant_share*
	
	gen indi=_n
	gen significant_share0=. // this is the baseline
	
	reshape long significant_share, i(indi) j(group)
	
	replace group=group+1 // 0-2 scale to 1-3 scale
	
	drop if significant_share==0 // drop all zero significance parameters (3rd category for groups with only 2 categories)
	replace significant_share=0 if significant_share==. // set all baseline categories to zero
	gen baseline=0
	replace baseline=1 if significant_share==0
	
	gsort variable_num  -group  // generate index for y-axis of plot
	gen id=_n
	
	// labeling
	
	gen group_description=""
	replace group_description="Ideology" if variable=="group_orientation"
	replace group_description="Political interest" if variable=="group_interest"
	replace group_description="Trust in government" if variable=="group_gov_trust"
	replace group_description="Age" if variable=="group_age"
	replace group_description="Education" if variable=="group_educ"
	replace group_description="Employment status" if variable=="group_employed"
	replace group_description="Language" if variable=="group_language"
	replace group_description="Religion" if variable=="group_religion"
	replace group_description="Residence" if variable=="group_urban"
	replace group_description="Income" if variable=="group_income"
	replace group_description="Party identification" if variable=="group_party_iden"

	gen group_member_descr=""
	replace group_member_descr="Left" if variable=="group_orientation" & group==1
	replace group_member_descr="Moderate" if variable=="group_orientation" & group==2
	replace group_member_descr="Right" if variable=="group_orientation" & group==3

	replace group_member_descr="Rather interested" if variable=="group_interest" & group==1
	replace group_member_descr="Rather not interested" if variable=="group_interest" & group==2

	replace group_member_descr="Trust" if variable=="group_gov_trust" & group==1
	replace group_member_descr="No trust" if variable=="group_gov_trust" & group==2
	
	replace group_member_descr="18-39" if variable=="group_age" & group==1
	replace group_member_descr="40-65" if variable=="group_age" & group==2
	replace group_member_descr=">65" if variable=="group_age" & group==3

	replace group_member_descr="Low" if variable=="group_educ" & group==1
	replace group_member_descr="Middle" if variable=="group_educ" & group==2
	replace group_member_descr="High" if variable=="group_educ" & group==3

	replace group_member_descr="Employed" if variable=="group_employed" & group==1
	replace group_member_descr="Unemployed" if variable=="group_employed" & group==2

	replace group_member_descr="German" if variable=="group_language" & group==1
	replace group_member_descr="French/Italian" if variable=="group_language" & group==2

	replace group_member_descr="Other" if variable=="group_religion" & group==1
	replace group_member_descr="Protestant" if variable=="group_religion" & group==2
	replace group_member_descr="Catholic" if variable=="group_religion" & group==3

	replace group_member_descr="Urban" if variable=="group_urban" & group==1
	replace group_member_descr="Rural" if variable=="group_urban" & group==2

	replace group_member_descr="Low" if variable=="group_income" & group==1
	replace group_member_descr="Middle" if variable=="group_income" & group==2
	replace group_member_descr="High" if variable=="group_income" & group==3
	
	replace group_member_descr="Other" if variable=="group_party_iden" & group==1
	replace group_member_descr="Leftist parties" if variable=="group_party_iden" & group==2
	replace group_member_descr="CVP" if variable=="group_party_iden" & group==3
	replace group_member_descr="FDP" if variable=="group_party_iden" & group==4
	replace group_member_descr="Rightist parties" if variable=="group_party_iden" & group==5

	
	bysort group_description: gen indi_group_descr=_n
	sort group_member_descr  
	bysort group_member_descr: gen indi_group_member_descr=_n 
	
	sort variable_num
	
	saveold ./vote_choice/votechoice_out.dta, replace version(12)
